package com.john.ishadowsocks.auto.config;

import com.john.http.core.convert.ComboValueConverter;
import com.john.http.core.convert.IntegerValueConverter;
import com.john.http.core.convert.SplitValueConverter;
import com.john.http.core.convert.Trim2NullValueConverter;
import com.john.http.core.parser.config.HtmlParseConfig;

/**
 * 〈一句话功能简述〉<br/>
 * 〈功能详细描述〉
 *
 * @author jiangguangtao on 2016/5/20.

 */
public class ShadowSocksConfigUtil {
    /**
     * 获取http://www.ishadowsocks.net/上的对应的配置信息
     *
     * @return
     */
    public static HtmlParseConfig getIShadowSocksConfig() {
        SplitValueConverter splitValueConverter = new SplitValueConverter("(:|：)", 1);

        ComboValueConverter stringConverter = new ComboValueConverter(splitValueConverter, new Trim2NullValueConverter());
        ComboValueConverter intConverter = new ComboValueConverter(splitValueConverter, new Trim2NullValueConverter(), new IntegerValueConverter());

        HtmlParseConfig config = HtmlParseConfig
                .build()
                .containerSelector("#free .container .row:eq(1)")
                .rowSelector("") //空表示 直接取子节点
                .colSelector("h4")
                .fieldMapping(0, "server", stringConverter)
                .fieldMapping(1, "serverPort", intConverter)
                .fieldMapping(2, "password", stringConverter)
                .fieldMapping(3, "encryptMethod", stringConverter)
                .fieldMapping(4, "status", stringConverter);


        return config;
    }
}
